const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  return [year, month, day].map(formatNumber).join('-')
}

// 深拷贝
const cloneTool = function (obj) {
  let initObj = null
  if (typeof obj === 'object' && obj !== null) {
    initObj = obj instanceof Array ? [] : {}
    for (let attr in obj) {
      initObj[attr] = cloneTool(obj[attr])
    }
  } else {
    initObj = obj
  }
  return initObj
}



const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime,
  cloneTool
}
